/**
 * @file GetNewMessagesProtocolMessage.cs
 * @author Zane Mayo
 * @date 7/5/2009
 */

using System;
using System.Collections.Generic;

namespace MxitAPI {
	
	
	public class RawMessage {
		
		public string ContactAddress { get; set; }
		public int Date { get; set; }
		public MessageType MessageType { get; set; }
		public int? Id { get; set; }
		public string Flags { get; set; }
		public string MessageText { get; set; }
		
		public RawMessage() {
		}
	}
	
	public class GetNewMessagesProtocolMessage : ProtocolMessage{
		
		//private List<RawMessage> rawMessages;
		private RawMessage rawMessage;
				
		public GetNewMessagesProtocolMessage() : base( ProtocolMessageType.GetNewMessages ) {
			//rawMessages = new List<RawMessage>();
			
		}
		
		/*public List<RawMessage> GetRawMessages() {
			// Todo maybe I should make a copy here
			return rawMessages;
		}*/
		
		public RawMessage GetRawMessage() {
			// Todo maybe I should make a copy here
			return rawMessage;
		}
		
		/*public void SetRawMessages( List<RawMessage> rawMessages ) {
			this.rawMessages = rawMessages;
		}*/
		
		public override void SetResponse ( string[][] response )
		{
			base.SetResponse (response);
			
			// Populate the List of raw messages with data returned from the server
			//for ( int i = 2 ; i < response.Length; i = i + 2 ) {
				
				// Check that a contact exists at this index. 
				// Mainly used for times when there are no new messages returned by Mxit
				//if ( response[i][0] == "" )
				//	continue;
				
				//RawMessage rawMessage;
			
			// If there are any new messages
			rawMessage = null;
			
			if ( response[2][0] != "" ) {
				rawMessage = new RawMessage();
				
				rawMessage.ContactAddress = response[2][0];
				rawMessage.Date = Int32.Parse( response[2][1] );
				rawMessage.MessageType = ( MessageType ) Int32.Parse( response[2][2] );
				if ( response[2][3] != "" )
					rawMessage.Id = Int32.Parse( response[2][3] );
				else
					rawMessage.Id = null;
				rawMessage.Flags = response[2][4];
				rawMessage.MessageText = response[3][0];
				//rawMessages.Add( rawMessage );
			//}
			}
		}
		
		
	}
}
